<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="lib/layui/css/layui.css"/>
		<style>
			.layui-form{
				padding-right: 20px;
			}
		</style>
	</head>
	<body>
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		  <legend>分类名称</legend>
		</fieldset>
		 
		<form class="layui-form" action="">
		  <div class="layui-form-item">
		    <label class="layui-form-label">分类名称</label>
		    <div class="layui-input-block">
		      <input type="text" name="name" lay-verify="title" autocomplete="off" placeholder="请输入名称" class="layui-input">
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">分类别名</label>
		    <div class="layui-input-block">
		      <input type="text" name="alias" lay-verify="title" autocomplete="off" placeholder="请输入别名" class="layui-input">
		    </div>
		  </div>
		  <div class="layui-form-item">
		      <div class="layui-input-block">
		        <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
		        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		      </div>
		    </div>
		</form>	
		<script src="layui/layui.js"></script>
		<script src="js/perapi.js"></script>	
		<script>		
			layui.use(['form','jquery',"layer"], function(){
			  var form = layui.form;
			  var layer=layui.layer;
			  var $=layui.jquery;		  			  
			  form.on('submit(demo1)', function(data){
			      console.log(data.field);				 
				  // 传过去吧数
				  $.ajax({
				  	method:"POST",
				  	url:"/my/article/addcates",
					data:data.field,				
				  	success: function(result){				  		
				  		console.log(result);						
						// 在查询一边数据												
						var tr=`
						<tr>	
								<input type="hidden" value="1">
								<td>${data.field.name}</td>
								<td>${data.field.alias}</td>
								<td>			
									<button type="button" class="layui-btn layui-btn-xs btnEdit btns1">编辑</button>
											<button type="button" class="layui-btn layui-btn-xs layui-btn-danger btns2">删除</button>		      
									</td>			
								</tr>
						`
						layer.msg('添加成功',function(){
							$(".tbody",window.parent.document).append(tr);
											  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
											  parent.layer.close(index); //再执行关闭 
						});
						
				  	}				
				  });
				  
					 
			      return false;
			  });			  		  
			})			
		</script>
	</body>
	
</html>
